package com.iyimo.core.mvc
{
	import com.iyimo.core.i.IController;
	import com.iyimo.event.Notification;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class Controller implements IController{
		private static var _listener:EventDispatcher;
		
		public function Controller(){}
		
		public static function initialize(listener:EventDispatcher):void{
			if (_listener == null)
				_listener = listener;
		}
		
		public function onRegister():void{}
		
		/**
		 * 派发notification,仿造puremvc,其实也是事件
		 */		
		protected function sendNotification(name:String, data:* = null):void{
			var n:Notification = new Notification(name);
			n.data = data;
			_listener.dispatchEvent(n);
		}
		
		protected function listenNotification(name:String, listener:Function):void{
			_listener.addEventListener(name, listener);
		}
		
		/**
		 * TODO 也许,cmd的发送和监听可以在不同的listener这哦给你
		 * 而不是,现在的,得到和监听在同一个里面,然后通过controller派发notifcation来实现
		 */		
		protected function addCmd(id:int, listener:Function):void{
			
		}
	}
}